#! /usr/bin/env python
# -*- coding: utf-8 -*-


import logging
import os
from datetime import datetime


def setup_logger():
    # 获取logs目录的地址
    log_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "\\logs"
    os.makedirs(log_dir, exist_ok=True)
    timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
    log_file = os.path.join(log_dir, f"test_{timestamp}.log")
    loggers = logging.getLogger("ui-automation")
    loggers.setLevel(logging.INFO)
    fh = logging.FileHandler(log_file)
    fh.setLevel(logging.INFO)
    ch = logging.StreamHandler()
    ch.setLevel(logging.INFO)
    formatter = logging.Formatter(
        "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
    )
    fh.setFormatter(formatter)
    ch.setFormatter(formatter)
    loggers.addHandler(fh)
    loggers.addHandler(ch)
    return loggers


logger = setup_logger()
